//
//  HCHomeProjectView.m
//  Aierle
//
//  Created by jiayibai-02por on 2017/6/19.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCHomeProjectView.h"

@interface HCHomeProjectView()
{
    UIImageView *projectLogo;
    UIImageView *centerImageView;
    UIImageView *leftImageView;
    UIImageView *rightImageView;
}

@end

@implementation HCHomeProjectView

- (instancetype)initWithFrame:(CGRect)frame {

    if (self = [super initWithFrame:frame]) {
        
        [self initializeView];
    }
    return self;
}

- (void)initializeView {
    
    UIImage *im = [UIImage imageNamed:@"项目展示"];
    projectLogo = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, YBKAdaptiveH(im.size.width), YBKAdaptiveH(im.size.height))];
    projectLogo.image = im;
    projectLogo.center = CGPointMake(Screen_width/2.0, projectLogo.center.y);
    projectLogo.backgroundColor = [UIColor clearColor];
    [self addSubview:projectLogo];
    
    centerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(projectLogo.frame), YBKAdaptiveW(157), YBKAdaptiveH(86))];
    centerImageView.center = CGPointMake(Screen_width/2.0, centerImageView.center.y);
    centerImageView.backgroundColor = [UIColor orangeColor];
    [self addSubview:centerImageView];
    
    leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, centerImageView.frame.origin.y, (Screen_width-YBKAdaptiveW(157))/2.0, YBKAdaptiveH(86))];
    leftImageView.backgroundColor = [UIColor orangeColor];
    [self addSubview:leftImageView];
    
    rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(centerImageView.frame), centerImageView.frame.origin.y, (Screen_width-YBKAdaptiveW(157))/2.0, YBKAdaptiveH(86))];
    rightImageView.backgroundColor = [UIColor orangeColor];
    [self addSubview:rightImageView];
    
    UIView *horizeLine = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(projectLogo.frame), Screen_width, 1)];
    horizeLine.backgroundColor = YBKRGBCOLOR(240, 240, 240, 1);
    [self addSubview:horizeLine];
    
    UIView *verticalLine1 = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(leftImageView.frame), CGRectGetMaxY(projectLogo.frame), 1, YBKAdaptiveH(86))];
    verticalLine1.backgroundColor =YBKRGBCOLOR(240, 240, 240, 1);
    [self addSubview:verticalLine1];
    
    UIView *verticalLine2 = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(centerImageView.frame), CGRectGetMaxY(projectLogo.frame), 1, YBKAdaptiveH(86))];
    verticalLine2.backgroundColor = YBKRGBCOLOR(240, 240, 240, 1);
    [self addSubview:verticalLine2];
    
    leftImageView.userInteractionEnabled = YES;
    centerImageView.userInteractionEnabled = YES;
    rightImageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClick1)];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClick2)];
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageClick3)];
    
    [leftImageView addGestureRecognizer:tap1];
    [centerImageView addGestureRecognizer:tap2];
    [rightImageView addGestureRecognizer:tap3];
}

- (void)setProjectArray:(NSArray *)projectArray {

    _projectArray = projectArray;
    if (projectArray.count > 0) {
        
        [leftImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[projectArray[0] objectForKey:@"path"]]] placeholderImage:nil];
    }
    if (projectArray.count > 1) {
        
        [centerImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[projectArray[1] objectForKey:@"path"]]] placeholderImage:nil];
    }
    if (projectArray.count > 2) {
        
        [rightImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[projectArray[2] objectForKey:@"path"]]] placeholderImage:nil];
    }
}

- (void)imageClick1 {

    if (self.didClickProjectImageBlock) {
        
        self.didClickProjectImageBlock(1);
    }
}

- (void)imageClick2 {

    if (self.didClickProjectImageBlock) {
        
        self.didClickProjectImageBlock(2);
    }
}

- (void)imageClick3 {

    if (self.didClickProjectImageBlock) {
        
        self.didClickProjectImageBlock(3);
    }
}

@end
